﻿using System;
using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;

namespace FileManager_Server.Utility
{
    public static class CryptographyGlobal
    {
        public static string Encode(string encryptString)
        {
            if (string.IsNullOrEmpty(encryptString)) return "";
            return Cryptographer.EncryptSymmetric(GlobalString.System_Config_String.ConfigDpapiCryptName, encryptString);
        }
        public static string Decode(string decryptString)
        {
            if (string.IsNullOrEmpty(decryptString)) return "";
            var result = string.Empty;
            try
            {
                result = Cryptographer.DecryptSymmetric(GlobalString.System_Config_String.ConfigDpapiCryptName, decryptString);
            }
            catch (Exception)
            {
                return decryptString;
            }
            return result;
        }

        public static string CreateHash(string plaintString)
        {
            return Cryptographer.CreateHash(GlobalString.System_Config_String.ConfigMd5TypeName, plaintString);
        }
        public static bool CompareHash(string plaintString, string hashedString)
        {
            return Cryptographer.CompareHash(GlobalString.System_Config_String.ConfigMd5TypeName, plaintString, hashedString);
        }
    }
}